<template>
  <el-dialog
    title="关闭"
    :visible="visible"
    @close="clearCloseRemark"
    width="560px"
    class="dialogInput"
  >
    <el-form label-width="80px">
      <el-form-item label="关闭说明">
        <el-input
          v-model="closeRemark"
          type="textarea"
          resize="none"
          style="height: 60px"
          maxlength="200"
          placeholder="请输入"
        ></el-input>
        <span style="color: #909399">将当前告警事件进行关闭</span>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="endOrder">确 定</el-button>
      <el-button @click="clearCloseRemark">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { batchEndWarningOrder } from "@/api/modules/eventManagement/eventManagement";
import { $getUrlParam } from "@/utils/public";

export default {
  name: "closeEventDialog",
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    orderData: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      closeRemark: "", // 关闭备注
    };
  },
  methods: {
    /**
     * 关闭
     * @returns {Promise<void>}
     */
    async endOrder() {
      let params = {
        warningOrderList: [
          {
            currentLink: this.orderData.linkId,
            warningOrderId: this.orderData.warningOrderId,
          },
        ],
        tenantId: this.$store.getters.userInfo.tenantId,
        alarmReason: this.orderData.alarmReason,
        deviceHorizontal: this.orderData.deviceHorizontal,
        devicePitch: this.orderData.devicePitch,
        closeRemark: this.closeRemark,
      };
      if (this.orderData.updateAddress) {
        params.address = this.orderData.address;
        params.longitude = this.orderData.longitude;
        params.latitude = this.orderData.latitude;
        params.gridId = this.orderData.gridId;
        params.gridName = this.orderData.gridName;
        params.horiAzimuthAngle = this.orderData.horiAzimuthAngle;
        params.checkGridFlag = "1"; // 是否修改网格员  1 是  0 否
      } else {
        params.checkGridFlag = "0";
      }
      params.warningTypeId = this.orderData.warningTypeId;
      batchEndWarningOrder(params).then((res) => {
        if (res.code === 200) {
          $message.success("关闭成功");
          const url =
            $getUrlParam("pageType") === "false"
              ? "/eventManagement"
              : "/myEvent32";
          this.$store.dispatch("tagsView/delView", this.$route);
          location.reload();
          this.$router.push(url);
        } else {
          $message.warning(res.msg);
        }
      });
      this.$emit("update:visible", false);
      this.closeRemark = "";
    },
    clearCloseRemark() {
      this.$emit("update:visible", false);
      this.closeRemark = "";
    },
  },
};
</script>

<style lang="scss" scoped>
.dialogInput {
  /deep/.el-dialog > .el-dialog__header {
    padding: 12px;
  }
  /deep/.el-dialog > .el-dialog__body {
    padding: 12px 60px 0;
  }
  /deep/.el-textarea__inner {
    height: 60px;
    width: 360px;
  }
  /deep/.el-form .el-form-item.el-form-item--small {
    margin-bottom: 0;
  }
  /deep/.el-dialog {
    border-radius: 4px;
  }
}
</style>
